import React from 'react'
import ReactDOM from 'react-dom'

function LoginBtn(props) {
  return (
    <button onClick={props.onClick}>登陆</button>
  )
};

function LogOutBtn(props) {
  return (
    <button onClick={props.onClick}>注销</button>
  )
};

class LoginControl extends React.Component {
  constructor(props) {
    super(props);
    this.handleLoginClick = this.handleLoginClick.bind(this);
    this.handleLogoutClick = this.handleLogoutClick.bind(this);
    this.state = { isLogin: false };
  };
  handleLoginClick() {
    this.setState({
      isLogin: true
    })
  };
  handleLogoutClick() {
    this.setState({
      isLogin: false
    })
  };
  render() {
    const isLogin = this.state.isLogin;
    return (
      <div>
        { isLogin ?
          <LogOutBtn onClick={this.handleLogoutClick} />
          : <LoginBtn onClick={this.handleLoginClick} />
        }
      </div>
    )
  }
};

ReactDOM.render (
  <LoginControl />,
  document.getElementById('root')
)